package com.infore.airsupervise.biz.impl;

import com.infore.airsupervise.app.Constants;
import com.infore.airsupervise.app.MsgConst;
import com.infore.airsupervise.bean.MissionE;
import com.infore.airsupervise.biz.MissionHandleBiz;
import com.infore.airsupervise.http.BaseResponse;
import com.infore.airsupervise.http.HttpAPI;
import com.infore.airsupervise.http.HttpCallBack;
import com.infore.airsupervise.http.HttpUtil;
import com.infore.airsupervise.http.OnServerResponseListener;
import com.infore.airsupervise.utils.DateUtil;
import com.infore.airsupervise.utils.JSONUtil;

import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;

/**
 * @features:
 * @author: WuTao
 * @date: 2017/4/13 15:37
 */
public class MissonHandleBizImpl implements MissionHandleBiz {
    @Override
    public Call<BaseResponse> commitMissionHandleRequest(String userId, String missionId, String discrib, final OnServerResponseListener<BaseResponse> listener) {

        Map<String , Object> params = new HashMap<>();
        params.put(Constants.MISSION_ID_KEY,missionId);
        params.put(Constants.USER_ID_KEY,userId);
        params.put("describ",discrib);
        Call<BaseResponse> call = HttpUtil.getHttpService().postParams(HttpAPI.COMMIT_MISSION_HANDLE,params);
        call.enqueue( new HttpCallBack(){
            @Override
            public void onSuccess(int operationCode, BaseResponse response) {
                super.onSuccess(operationCode, response);
                listener.onSucceed(response, MsgConst.OPERATION_SUCCESS);
            }

            @Override
            public void onFailed(int operationCode, String desc) {
                super.onFailed(operationCode, desc);
                listener.onFailed(operationCode,MsgConst.OPERATION_FAILED,desc);
            }

            @Override
            public void onException(int errorCode, String title, String desc) {
                super.onException(errorCode, title, desc);
                listener.onFailed(errorCode,title,desc);
            }
        });
        return call;
    }

    @Override
    public Call<BaseResponse> commitMissionExamineRequest(String userId, String missionId, String discrib,int isEnter, final OnServerResponseListener<BaseResponse> listener) {
        Map<String , Object> params = new HashMap<>();
        params.put(Constants.MISSION_ID_KEY,missionId);
        params.put(Constants.USER_ID_KEY,userId);
        params.put("describ",discrib);
        params.put("state",isEnter);//1 通过 0不通过
       // params.put("time", DateUtil.getCurrentDateStr(true));
        Call<BaseResponse> call = HttpUtil.getHttpService().postParams(HttpAPI.COMMIT_MISSION_EXAMNIE,params);
        call.enqueue( new HttpCallBack() {
            @Override
            public void onSuccess(int operationCode, BaseResponse response) {
                super.onSuccess(operationCode, response);
                listener.onSucceed(response,MsgConst.OPERATION_SUCCESS);
            }

            @Override
            public void onFailed(int operationCode, String desc) {
                super.onFailed(operationCode, desc);
                listener.onFailed(operationCode,MsgConst.OPERATION_FAILED,desc);
            }

            @Override
            public void onException(int errorCode, String title, String desc) {
                super.onException(errorCode, title, desc);
                listener.onFailed(errorCode,title,desc);
            }
        });
        return call;
    }
}
